package com.jk.util;

import com.jk.entity.account.AccMenu;
import com.jk.entity.account.AccPermission;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import java.util.*;

/**
 * Created by yang on 15/9/25.
 */
public class AccountUtil {

    public static List<Map<String, Object>> getShowPermissions(Set<String> permissionIdSet, List<AccPermission> permissionList, String parentId) {
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
        for (AccPermission permission : permissionList) {
            if (parentId.equals(permission.getAccPermissionParentId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", permission.getAccPermissionId());
                map.put("text", permission.getAccPermissionName());
                map.put("key", permission.getAccPermissionKey());
                map.put("checked", permissionIdSet.contains(permission.getAccPermissionId()));
                map.put("order", permission.getAccPermissionOrder());
                map.put("children", getShowPermissions(permissionIdSet, permissionList, permission.getAccPermissionId()));
                mapList.add(map);
            }
        }
        return mapList;
    }

    public static List<String> getChildrenPermissionIds(String parentId, List<AccPermission> permissions) {
        List<String> list = new ArrayList<String>();
        for (AccPermission permission : permissions) {
            if (parentId.equals(permission.getAccPermissionParentId())) {
                list.add(permission.getAccPermissionId());
                list.addAll(getChildrenPermissionIds(permission.getAccPermissionId(), permissions));
            }
        }
        return list;
    }

}
